
using System;
using System.Collections.Generic;
using System.Diagnostics;
using MathNet.Numerics.LinearAlgebra;
using igather.Framework;

namespace Test
{
	
	
	public static class Utilities
	{
		
		public static void Print(Matrix m)
		{
			for (int row = 0; row < m.RowCount; row++)
			{
				for (int column = 0; column < m.ColumnCount; column++)
				{
					Console.Write(string.Format("{0:0.0000}",m[row, column]) + "\t");
				}
				Console.WriteLine();
			}
			Console.WriteLine();
		}
		
		public static IGraph GenerateGraph(int size, int clusters, IGraph g)
		{
			List<Vertex> vertices = new List<Vertex>();
			for (int i = 0; i < size; i++)
				vertices.Add(new Vertex(i.ToString()));
			IGraph graph = g;
			foreach (Vertex v in vertices)
				graph.AddVertex(v);
			Random r = new Random();
			for (int i = 0; i < (Math.Pow(vertices.Count, 2)/4); i++)
			{
				int node1 = (r.Next(0, (vertices.Count - 1)/clusters)*clusters)+(i%clusters);
				int node2 = (r.Next(0, (vertices.Count - 1)/clusters)*clusters)+(i%clusters);
				double w = r.NextDouble();
				if (i > ((Math.Pow(vertices.Count, 2)/4)-10))
				{
					node2 = (r.Next(0, (vertices.Count - 1)/clusters)*clusters)+((i+1)%clusters);
					w = r.NextDouble()/5;
				}
				Edge e1 = graph.CreateEdge(graph.Vertices[node1], graph.Vertices[node2]);
				//Edge e2 = graph.CreateEdge(graph.Vertices[node2], graph.Vertices[node1]);
				e1.Weight = w;
				//e2.Weight = w;
				graph.AddEdge(e1);
				//graph.AddEdge(e2);
			}
			
			return graph;
		}
	}
	
	public static class Assert
	{
		public class AssertException : Exception
		{
			public AssertException()
			{
			}
			
			public AssertException(string message) : base(message)
			{
			}
		}
		
		public static void IsTrue(bool condition)
		{
			IsTrue(condition, "Condition was false, expected true");
		}
		
		public static void IsTrue(bool condition, string message)
		{
			if (!condition)
				throw new AssertException(message);
		}
		
		public static void IsFalse(bool condition)
		{
			IsFalse(condition, "Condition was true, expected false");
		}
		
		public static void IsFalse(bool condition, string message)
		{
			if (condition)
				throw new AssertException(message);
		}
		
		public static void AreEqual(object obj1, object obj2)
		{
			AreEqual(obj1, obj2, "Objects are not equal, expected equal");
		}
		
		public static void AreEqual(object obj1, object obj2, string message)
		{
			if (!obj1.Equals(obj2))
				throw new AssertException(message);
		}
		
		public static void AreNotEqual(object obj1, object obj2)
		{
			AreNotEqual(obj1, obj2, "Objects are equal, expected not equal");
		}
		
		public static void AreNotEqual(object obj1, object obj2, string message)
		{
			if (obj1.Equals(obj2))
				throw new AssertException(message);
		}
		
		public static void IsNull(object obj)
		{
			IsNull(obj, "Object is not null, expected null");
		}
		
		public static void IsNull(object obj, string message)
		{
			if (obj != null)
				throw new AssertException(message);
		}
		
		public static void IsNotNull(object obj)
		{
			IsNotNull(obj, "Object is null, expected not null");
		}
		
		public static void IsNotNull(object obj, string message)
		{
			if (obj == null)
				throw new AssertException(message);
		}
	}
}
